#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 20010;
int dp[N];
int g[N];
int q[N];
int main()
{
    int n,m;
    cin >> n >> m;
    for(int i=1;i<=n;i++)
    {
        memcpy(g,dp,sizeof(dp));
        int v,w,s;
        cin >> v >> w >> s;
        for(int j=0;j<v;j++)
        {
            int h=0,t=-1;
            for(int k=j;k<=m;k+=v)
            {
                if(h<=t&&q[h]<k-v*s) h++;
                if(h<=t) dp[k]=max(g[k],g[q[h]]+(k-q[h])/v*w);
                while(h<=t&&g[k]>=(g[q[t]]+(k-q[t])/v*w)) t--;
                q[++t]=k;
            }
        }
    }
    cout << dp[m] << endl;
    return 0;
}